import pygame

def mission():
    import Main
    # 背景颜色填充白色

    bg_pic = pygame.image.load("../Docs/images/b5.jpg")
    from Main import screen
    screen.blit(pygame.transform.scale(bg_pic, (1120, 630)), (0, 0))
    Main.screen.blit(bg_pic, (0, 0))

    # 设置标题
    word = "选关"
    word_location = (380, 20)
    font = pygame.font.Font("../Docs/images/WenDingTeYanKai-2.ttf", 25)
    text = font.render(word, True, (0, 0, 0))
    Main.screen.blit(text, word_location)

    # 绘制关卡
    from PublicTools import button
    _mission = 1

    button_size = (100, 100)
    y = 100
    while y < 400:
        x = 120
        while x < 700:
            if button((x, y), button_size, str(_mission), 14, (x+40, y+40), "../Docs/images/button1.png"):
                Main.chosen_mission = _mission
                return 3
            _mission += 1
            x += 120
        y += 80
    scene = 2
    button_size = (150, 50)
    if button((20, 20), button_size, "返回", 14, (80, 35), "../Docs/images/button1.png"):
        scene = 0
    return scene


# 养成界面
def buildup():

    # 背景
    bg_pic = pygame.image.load("../Docs/images/b9.jpg")
    from Main import screen
    screen.blit(pygame.transform.scale(bg_pic, (1120, 630)), (0, 0))
    screen.blit(bg_pic, (0, 0))

    # 设置标题
    word = "养成界面"
    word_location = (500, 20)
    font = pygame.font.Font("../Docs/images/WenDingTeYanKai-2.ttf", 25)
    text = font.render(word, True, (0, 0, 0))
    screen.blit(text, word_location)

    # 设置人物肖像
    # image_size = (100, 100)
    # image_location = (200, 100)
    # man = pygame.image.load("../Docs/images/man.png")
    # man = pygame.transform.scale(man, image_size)
    # screen.blit(man, image_location)

    # 设置人物信息
    from Main import user
    pygame.draw.rect(screen, [0, 0, 0], [120, 150, 100, 30], 1)
    font = pygame.font.Font("../Docs/images/SourceHanSerif-Light.ttc", 15)
    text = font.render('昵称', True, (0, 0, 0))
    screen.blit(text, (80, 150))
    text = font.render(user.username, True, (0, 0, 0))
    screen.blit(text, (150, 150))

    pygame.draw.rect(screen, [0, 0, 0], [120, 350, 100, 30], 1)
    font = pygame.font.Font("../Docs/images/SourceHanSerif-Light.ttc", 15)
    text = font.render('基础数值', True, (0, 0, 0))
    screen.blit(text, (50, 350))
    text = font.render(str(user.weight), True, (0, 0, 0))
    screen.blit(text, (150, 350))

    # 显示养成素材
    # x = 380
    # while x < 580:
    #    y = 205
    #    while y < 405:
    #        pygame.draw.rect(screen, [0, 0, 0], [x, y, 50, 50], 1)
    #        y += 50
    #    x += 50

    font = pygame.font.Font("../Docs/images/SourceHanSerif-Light.ttc", 20)
    text = font.render('养成素材', True, (0, 0, 0))
    screen.blit(text, (600, 70))
    if user.buildup_num != 0:
        print(1)

    # 设置修改昵称键
    from PublicTools import button
    import easygui as g
    button_size = (100, 30)
    if button((120, 190), button_size, "修改", 14, (150, 200), "../Docs/images/button1.png"):
        value = g.enterbox(msg="请输入修改后的昵称：", title="修改昵称")
        user.username = value
        g.msgbox("昵称成功修改为：" + value)
    if button((700, 65), button_size, "使用", 14, (735, 75), "../Docs/images/button1.png"):
        if user.buildup_num!=0:
            from buildup_material import Material
        else:
            print("无材料")

    # 设置返回键
    scene = 1
    if button((10, 10), (60,20), "返回", 14, (30, 12), "../Docs/images/button1.png"):
        scene = 0
    return scene
